package com.yami.shop.admin.controller;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.common.util.PageParam;

import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.yami.shop.service.RechargePackageService;
import com.yami.shop.bean.model.RechargePackage;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

/**
 * <p>
 * 充值套餐 前端控制器
 * </p>
 *
 * @author chajiu
 * @since 2021-06-29
 */
@RestController
@RequestMapping("/recharge-package")
public class RechargePackageController {


    @Autowired
    private RechargePackageService RechargePackageService;


    /**
     * 分页获取
    */
     @GetMapping("/page")
     @PreAuthorize("@pms.hasPermission('admin:RechargePackage:page')")
     public ResponseEntity<IPage<RechargePackage>> page(RechargePackage entity,PageParam<RechargePackage> page) {
         IPage<RechargePackage> iPage = RechargePackageService.page(page, new LambdaQueryWrapper<RechargePackage>());
         return ResponseEntity.ok(iPage);
     }

    /**
     * 保存
     */
    @PostMapping("/save")
    @PreAuthorize("@pms.hasPermission('admin:RechargePackage:save')")
    public ResponseEntity<Void> save(@RequestBody RechargePackage entity) {
        RechargePackageService.save(entity);
        return ResponseEntity.ok().build();
    }

    /**
     * 获取信息
     */
    @GetMapping("/info/{id}")
    @PreAuthorize("@pms.hasPermission('admin:RechargePackage:info')")
    public ResponseEntity<RechargePackage> info(@PathVariable("id") String id){
        RechargePackage entity = RechargePackageService.getById(id);
            return ResponseEntity.ok(entity);
    }

    /**
     * 修改
     */
    @PutMapping
    @PreAuthorize("@pms.hasPermission('admin:RechargePackage:update')")
    public ResponseEntity<Void> update(@RequestBody RechargePackage entity){
        RechargePackageService.updateById(entity);
            return ResponseEntity.ok().build();
    }

    /**
     * 删除
     */
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('admin:RechargePackage:delete')")
    public ResponseEntity<Void> delete(@RequestBody String[]ids){
        RechargePackageService.removeByIds(Arrays.asList(ids));
            return ResponseEntity.ok().build();
    }


}

